<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.pizzaonline.utils.*"%>
<%@ page import="com.pizzaonline.JDBC.*"%>
<%@ page import="java.sql.*" %>
<jsp:include page="hautDePage.jsp" flush="true">
	<jsp:param name="title" value="Modification d'une pizza" />
</jsp:include>

<div class="blocTexte">
<h3>Modification d'une pizza</h3>
<a href="index.jsp" >Retour à l'accueil</a>
<br /> 

<%
	//Utils.printHeader(out, "Modification", "css/style.css",null);
	String nomPizza = request.getParameter("pizza");
%>

<%
	out.println("<form action=\"ModificationPizza\" method=\"post\">");
	out.println("<table align=\"center\">");
	out.println("<tr><td><label>Nom : </label></td>");
	out.println("<td><input type=\"text\" size=\"20\" name= \"nom_pizza\" value=\""+nomPizza+"\" readonly /></td></tr>");
	out.println("<tr><td><label>Ingrédients : </label></td>");
	out.println("<td>");
	
	//Récupération des ingrédients de pizza depuis la base
	
	try{
		String ingredient;
		DataBase db = new DataBase();
		db.connexionBD();
		XMLControler.readXMLFile("carte.xml");

		ResultSet rs = db.select("nom", "stock", "depizza=true");
		while (rs.next()){
			ingredient = rs.getString("nom");
			System.out.println("Ingrédient : "+ingredient);
			
			//On teste si l'ingrédient est présent dans la pizza
			if(XMLControler.isContainedByPizza(ingredient,nomPizza)){
				out.println("<input type=\"checkbox\" name=\"ingredients\" value=\""+ingredient+"\" checked />"+ingredient);
			}
			else{
				out.println("<input type=\"checkbox\" name=\"ingredients\" value=\""+ingredient+"\" />"+ingredient);
			}
		}
		db.closeConnection();
	}
	catch(Exception e){
		e.printStackTrace();
	}
	
	out.println("</tr>");
	
	out.println("<tr align=\"center\"><td colspan=\"2\">");
	out.println("<input type=\"submit\" value=\"Valider\" />");
	out.println("<input type=\"reset\" value=\"Réinitialiser\" /></td></tr>");
	out.println("</table></form>");
%>

</div>
<jsp:include page="basDePage.jsp" flush="true" />
<%
	//Utils.printFooter(out);
%>